package validator.handle;

import java.lang.annotation.Annotation;

import validator.annotation.Max;
import validator.exception.ValidateException;

public class MaxValidator extends RangeValidator {

	@Override
	public void validate(Annotation annotation, Object v) {
		double size = Double.MIN_VALUE;
		if (v.getClass() == String.class) {
			size = ((String) v).length();
		} else {
			size = ((Number) v).doubleValue();
		}

		Max anno = (Max) annotation;
		if (size > anno.max())
			throw new ValidateException(anno.value());
	}
}
